package net.hn.hnms.biz.plan.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.plan.request.PlanDrivageReq;
import net.hn.hnms.biz.plan.service.IPlanDrivageService;
import net.hn.hnms.biz.plan.vo.PlanDrivageVO;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 掘进计划
 *
 * @author zhaoyang
 * @date 2022-07-29
 */

@Api(value = "掘进计划模块", tags = {"掘进计划"})
@RestController
@RequestMapping("/drivage")
public class PlanDrivageController extends BaseController {


    @Autowired
    private IPlanDrivageService drivingPlanService;


    /**
     * 新增掘进计划
     */
    @ApiOperation("新增掘进计划")
    @SaCheckPermission("plan:drivage:add")
    @PostMapping("/add")
    @Log(title = "新增掘进计划", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody PlanDrivageReq planDrivage) {
        drivingPlanService.insert(planDrivage);
        return R.ok();
    }

    /**
     * 删除掘进计划
     */
    @ApiOperation("删除掘进计划")
    @SaCheckPermission("plan:drivage:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除掘进计划", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        drivingPlanService.deleteBatch(idList);
        return R.ok();
    }


    /**
     * 修改掘进计划
     */
    @ApiOperation("修改掘进计划")
    @SaCheckPermission("plan:drivage:update")
    @PutMapping("/update")
    @Log(title = "修改掘进计划", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody PlanDrivageReq planDrivage) {
        drivingPlanService.updateById(planDrivage);
        return R.ok();
    }

    /**
     * 启用/禁用
     */
    @ApiOperation("启用/禁用")
    @SaCheckPermission("plan:drivage:status:change")
    @PutMapping("/status/change/{id}/{status}")
    public R<Void> changeStatus(@PathVariable("id") String id, @PathVariable("status") Integer status) {
        drivingPlanService.changeStatus(id, status);
        return R.ok();
    }

    /**
     * 获取掘进计划列表
     */
    @ApiOperation("获取掘进计划分页列表")
//    @SaCheckPermission("plan:drivage:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<PlanDrivageVO>> page(PlanDrivageReq planDrivage, PageQuery pageQuery) {
        return R.ok(drivingPlanService.selectPageList(planDrivage, pageQuery));
    }

    /**
     * 获取掘进计划列表
     */
    @ApiOperation("获取掘进计划列表")
//    @SaCheckPermission("plan:drivage:list")
    @GetMapping("/list")
    public R<List<PlanDrivageVO>> list(PlanDrivageReq planDrivage) {
        return R.ok(drivingPlanService.selectList(planDrivage));
    }

    /**
     * 获取掘进计划详情
     */
    @ApiOperation("获取掘进计划详情")
//    @SaCheckPermission("plan:drivage:detail")
    @GetMapping("/{id}")
    public R<PlanDrivageVO> detail(@PathVariable("id") String id) {
        return R.ok(drivingPlanService.selectDetailById(id));
    }


}
